<script setup>
import { Search } from '@element-plus/icons-vue'
import { useAppendixStore, useSubjectStore } from '@/stores'
import { ref } from 'vue'
const appendixStore = useAppendixStore()
const subjectStore = useSubjectStore()
const search = ref('')
const loading = ref(false)
const is = ref(true)
is.value = subjectStore.is
appendixStore.getSAE()
const degree = [
  {
    value: 1,
    label: '轻度'
  },
  {
    value: 2,
    label: '中度'
  },
  {
    value: 3,
    label: '重度'
  }
]
const conversions = [
  {
    label: '症状消失',
    options: [
      {
        value: 1,
        label: '有后遗症'
      },
      {
        value: 2,
        label: '无后遗症'
      }
    ]
  },
  {
    label: '症状持续',
    options: [
      {
        value: 3,
        label: '症状持续'
      }
    ]
  }
]
const situations = [
  {
    label: '国内',
    options: [
      {
        value: 1,
        label: '有'
      },
      {
        value: 2,
        label: '无'
      },
      {
        value: 3,
        label: '不详'
      }
    ]
  },
  {
    label: '国外',
    options: [
      {
        value: 4,
        label: '有'
      },
      {
        value: 5,
        label: '无'
      },
      {
        value: 6,
        label: '不详'
      }
    ]
  }
]
const addsearch = async (data) => {
  loading.value = true
  if (data.length === 0) {
    await appendixStore.getSAE()
  } else {
    await appendixStore.searchSAE(data)
  }
  loading.value = false
}
</script>
<template>
  <div v-if="!is">
    <el-input
      style="width: 200px; margin-right: 10px"
      v-model="search"
      :prefix-icon="Search"
    />
    <el-button @click="addsearch(search)">搜索</el-button>
  </div>
  <el-card class="page-container">
    <div v-if="is" class="header">
      <span>严重不良事件</span>
      <div>
        <el-input
          style="width: 200px; margin-right: 10px"
          v-model="search"
          :prefix-icon="Search"
        />
        <el-button @click="addsearch(search)">搜索</el-button>
      </div>
    </div>
    <el-table
      v-loading="loading"
      :data="appendixStore.SAE"
      :style="{ width: '100%' }"
    >
      <el-table-column prop="idName" label="姓名" width="90" />
      <el-table-column prop="type" label="报告类型" width="130" />
      <el-table-column label="报告时间" width="140">
        <template #default="scope">
          <el-date-picker
            v-model="scope.row.date"
            type="date"
            placeholder="报告时间"
            disabled
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="SAE发生时间" width="140">
        <template #default="scope">
          <el-date-picker
            v-model="scope.row.occurrenceDate"
            type="date"
            placeholder="发生时间"
            disabled
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="SAE反应严重程度" width="140">
        <template #default="scope">
          <el-select
            v-model="scope.row.degree"
            placeholder="Select"
            disabled
            style="width: 100px"
          >
            <el-option
              v-for="item in degree"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="SAE转归" width="124">
        <template #default="scope">
          <el-select
            v-model="scope.row.conversion"
            placeholder="Select"
            disabled
            style="width: 100px"
          >
            <el-option-group
              v-for="group in conversions"
              :key="group.label"
              :label="group.label"
            >
              <el-option
                v-for="item in group.options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-option-group>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="SAE报告情况" width="124">
        <template #default="scope">
          <el-select
            v-model="scope.row.situation"
            placeholder="Select"
            style="width: 100px"
            disabled
          >
            <el-option-group
              v-for="group in situations"
              :key="group.label"
              :label="group.label"
            >
              <el-option
                v-for="item in group.options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-option-group>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="handle" label="SAE发生及处理的详细情况" />
    </el-table>
  </el-card>
</template>
<style lang="scss" scoped>
.page-container {
  min-height: 100%;
  box-sizing: border-box;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
